package com.sky.mapper;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {
    //根据userId和shoppingCartDTO信息查询对应的shoppingCart对象
    List<ShoppingCart> list(ShoppingCart  shoppingCart);

    //根据id修改(增加)商品数量
    @Update("update shopping_cart set number = #{number} where id = #{id}")
    void updateNumberById(ShoppingCart shoppingCart);

    //插入购物车数据
    @Insert("insert into shopping_cart (name, image, user_id, dish_id, setmeal_id, dish_flavor,number, amount, create_time) " +
            "VALUES" +
            "(#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{createTime})")
    void insert(ShoppingCart shoppingCart);

    @Select("select * from shopping_cart where user_id = #{userId}")
    List<ShoppingCart> showShoppingCart(Long userId);

    @Delete("delete from shopping_cart where user_id = #{userId}")
    void cleanShoppingCart(Long userId);

    //单个商品数量-1
    //void subShoppingCart(ShoppingCart shoppingCart, Long userId);

    //获取购物车商品对应的数量
    Integer getNumber(ShoppingCartDTO shoppingCartDTO,Long userId);

    //商品数量为0，从购物车中删去这条数据
    void deleteShoppingCart(ShoppingCartDTO shoppingCartDTO,Long userId);
}
